package com.tianyu.service.mqtt.handler.outbound;

import com.alibaba.fastjson2.JSONObject;
import com.tianyu.service.mqtt.common.MqttClientOptions;
import jakarta.annotation.Resource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**********************************
 * @Author YSW
 * @Description 指令发送
 * @Date 2024/8/2 - 17:56
 **********************************/

@Slf4j
@Service
public class CommandSendService {

    @Resource
    private IMqttOutboundMessageGateway mqttOutboundMessageGateway;

    @Resource
    private IMqttOutboundThird01Gateway mqttOutboundThird01Gateway;

    @Resource
    private MqttClientOptions mqttClientOptions;


    public void publishThird01(String topic, JSONObject params) {
        mqttOutboundThird01Gateway.publish(topic, params.toJSONString().getBytes());
    }


    public void publishCommand(Integer companyId, String deviceSn, Integer instructId, JSONObject params) {
        final JSONObject builtParams = buildParams(instructId, params);
        log.info(builtParams.toJSONString());
        mqttOutboundMessageGateway.publish(mqttClientOptions.getOutboundTopicPrefix().getCommand() + companyId + "/" + deviceSn,
                builtParams.toJSONString().getBytes());
    }

    private JSONObject buildParams(Integer instructId, JSONObject otherParams) {
        final JSONObject object = JSONObject.of(
                "userId", "440311",
                "userName", "大鹏新区",
                "instructId", instructId
        );
        if (otherParams != null) {
            object.putAll(otherParams);
        }
        return object;
    }

    @Getter
    public enum UavCommand {
        COMMAND_1001(1001, "飞行控制"),
        COMMAND_1002(1002, "起飞"),
        COMMAND_1003(1003, "降落"),
        COMMAND_1004(1004, "取消降落"),
        COMMAND_1005(1005, "强制降落"),
        COMMAND_1006(1006, "航线规划"),
        COMMAND_1007(1007, "返航"),
        COMMAND_1008(1008, "取消返航"),
        COMMAND_1009(1009, "航线开始"),
        COMMAND_1010(1010, "航线暂停"),
        COMMAND_1011(1011, "航线恢复"),
        COMMAND_1012(1012, "航线结束"),
        COMMAND_1013(1013, "修改返航高度"),
        COMMAND_1014(1014, "修改Home点"),
        COMMAND_1015(1015, "开始打点飞行"),
        COMMAND_1016(1016, "停止打点飞行"),
        COMMAND_1017(1017, "切换飞行控制权"),
        COMMAND_1018(1018, "紧急制动");

        private final int code;
        private final String desc;

        UavCommand(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }


    @Getter
    public enum UavCameraCommand {
        COMMAND_1101(1101, "云台向上转动"),
        COMMAND_1102(1102, "云台向右上转动"),
        COMMAND_1103(1103, "云台向右转动"),
        COMMAND_1104(1104, "云台向右下转动"),
        COMMAND_1105(1105, "云台向下转动"),
        COMMAND_1106(1106, "云台向左下转动"),
        COMMAND_1107(1107, "云台向左转动"),
        COMMAND_1108(1108, "云台向左上转动"),
        COMMAND_1109(1109, "云台回中"),
        COMMAND_1110(1110, "停止转动"),
        COMMAND_1111(1111, "相机变倍加"),
        COMMAND_1112(1112, "相机变倍减"),
        COMMAND_1113(1113, "相机变倍停止"),
        COMMAND_1114(1114, "相机变倍复位"),
        COMMAND_1115(1115, "切换相机"),
        COMMAND_1116(1116, "切换相机视频源"),
        COMMAND_1117(1117, "切换相机模式"),
        COMMAND_1118(1118, "拍照"),
        COMMAND_1119(1119, "开始录像"),
        COMMAND_1120(1120, "停止录像"),
        COMMAND_1121(1121, "切换视频清晰度"),
        COMMAND_1122(1122, "对焦"),
        COMMAND_1123(1123, "自动拍照"),
        COMMAND_1124(1124, "云台指点转动"),
        COMMAND_1125(1125, "激光测距"),
        COMMAND_1126(1126, "相机变倍绝对值"),
        COMMAND_1127(1127, "云台速度控制"),
        COMMAND_1128(1128, "对焦+测距"),
        COMMAND_1129(1129, "云台角度绝对值控制"),
        COMMAND_1130(1130, "打开/关闭实时图片传输"),
        COMMAND_1131(1131, "格式化相机存储卡");

        private final int code;
        private final String desc;

        UavCameraCommand(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }

    @Getter
    public enum UavMegaphoneCommand {
        COMMAND_1200(1200, "文字喊话"),
        COMMAND_1201(1201, "即时喊话开始"),
        COMMAND_1202(1202, "即时喊话结束"),
        COMMAND_1203(1203, "即时喊话"),
        COMMAND_1204(1204, "录音喊话"),
        COMMAND_1205(1205, "喊话停止"),
        COMMAND_1206(1206, "喊话音量"),
        COMMAND_1207(1207, "喊话循环"),
        COMMAND_1208(1208, "切换喊话器模式");

        private final int code;
        private final String desc;

        UavMegaphoneCommand(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }

}
